package com.enjoyor.soa.traffic.core.efoms.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.enjoyor.soa.traffic.core.efoms.domain.CheckDeviceInfo;
import com.enjoyor.soa.traffic.core.efoms.mapper.ICheckDeviceInfoMapper;
import com.enjoyor.soa.traffic.core.efoms.service.ICheckDeviceInfoService;
import com.enjoyor.soa.traffic.util.helper.LoggerHelper;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

@Service
@Transactional
@SuppressWarnings("rawtypes")
public class CheckDeviceInfoService implements ICheckDeviceInfoService{

	@Autowired
	private ICheckDeviceInfoMapper CheckDeviceInfoMapper;

	/**
	 * 获取巡检设备分页；
	 */
	@Override
	public Page getCheckDeviceInfoPage(String DevId,String devTypeCode,String devName,String ledType,String devStatusCode,String isPingConnect,String checkResultCode,String devAreaCode,String isDelayData,String isHightPackage,String isHightResponse,String isHaveData,String devFactory,String searchFlag,String beginLastPassTime,String endLastPassTime,String isPhotoSuccess,String repStatusCode,String project,String company,String picStatusFlag,Page page) {
		// TODO Auto-generated method stub
		Map<String, Object> paramT = this.getSelectMap(DevId,devTypeCode,devName,ledType,devStatusCode,isPingConnect,checkResultCode,devAreaCode,isDelayData,isHightPackage,isHightResponse,isHaveData,devFactory,searchFlag,beginLastPassTime,endLastPassTime,isPhotoSuccess,repStatusCode,project,company,picStatusFlag);
		page.setMapBean(paramT);
		return this.CheckDeviceInfoMapper.selectCheckDeviceInfoPage(page);
	}

	/**
	 * 获取巡检设备list；
	 */
	@Override
	public List<CheckDeviceInfo> getCheckDeviceInfoList(String DevId,String devTypeCode,String devName,String ledType,String devStatusCode,String isPingConnect,String checkResultCode,String devAreaCode,String isDelayData,String isHightPackage,String isHightResponse,String isHaveData,String devFactory,String searchFlag) {
		// TODO Auto-generated method stub
		Map<String, Object> paramT = this.getSelectMap(DevId,devTypeCode,devName,ledType,devStatusCode,isPingConnect,checkResultCode,devAreaCode,isDelayData,isHightPackage,isHightResponse,isHaveData,devFactory,searchFlag,null,null,null,null,null,null,null);
		return this.CheckDeviceInfoMapper.selectCheckDeviceInfoList(paramT);
	}

	/**
	 * 获取巡检设备对象信息；
	 */
	@Override
	public CheckDeviceInfo getCheckDeviceInfo(String DevId) {
		// TODO Auto-generated method stub
		return this.CheckDeviceInfoMapper.selectById(DevId);
	}
	
	@Override
	public ResultPojo getCheckCount(String beginTime, String endTime,String devTypeCode) {
		// TODO Auto-generated method stub
		Map<String, Object> map = new HashMap<>();
		Map<String,Object> mapSuccess = new HashMap<>();
		Map<String,Object> mapFault = new HashMap<>();
		mapSuccess.put("key", "1");
		mapSuccess.put("devTypeCode", devTypeCode);
		mapFault.put("devTypeCode", devTypeCode);
		mapFault.put("key", "0");
		map.put("beginTime", beginTime);
		map.put("endTime", endTime);
		map.put("devTypeCode", devTypeCode);
		try {
			int warnCount = this.CheckDeviceInfoMapper.getCheckWarnCount(map);
			int noCheckCount = this.CheckDeviceInfoMapper.getCheckNoCheckCount(map);
			int repairsCount = this.CheckDeviceInfoMapper.getCheckRepairsCount(map);
			int seriousCount = this.CheckDeviceInfoMapper.getCheckSeriousCount(map);
			int CheckCount = this.CheckDeviceInfoMapper.getCheckCheckCount(map);
			int netStatusSuccessCount = 0;
			int netStatusFaultCount = 0;
			int picHaveSuccessCount = 0;
			int picHaveFaultCount = 0;
			int picMassSuccessCount = 0;
			int picMassFaultCount = 0;
			int DataStatusSuccessCount = 0;
			int dataStatusFaultCount = 0;
			int daleyStatusSuccessCount = 0;
			int daleyStatusFaultCount = 0;
			Map<String,Object> resultPojoMap = new HashMap<>();
			resultPojoMap.put("warnCount", warnCount);
			resultPojoMap.put("noCheckCount", noCheckCount);
			resultPojoMap.put("repairsCount", repairsCount);
			resultPojoMap.put("seriousCount", seriousCount);
			resultPojoMap.put("CheckCount", CheckCount);
			ResultPojo resultPojo = new ResultPojo();
			if(devTypeCode.equals("REPDEVTYPE01")){//信号机；
				netStatusSuccessCount = this.CheckDeviceInfoMapper.getNetStatusCount(mapSuccess);
				netStatusFaultCount = this.CheckDeviceInfoMapper.getNetStatusCount(mapFault);
				resultPojoMap.put("netStatusSuccessCount", netStatusSuccessCount);
				resultPojoMap.put("netStatusFaultCount", netStatusFaultCount);
			}else if(devTypeCode.equals("REPDEVTYPE02")){//视频监控；
				netStatusSuccessCount = this.CheckDeviceInfoMapper.getNetStatusCount(mapSuccess);
				netStatusFaultCount = this.CheckDeviceInfoMapper.getNetStatusCount(mapFault);
				picHaveSuccessCount = this.CheckDeviceInfoMapper.getHavePicCount(mapSuccess);
				picHaveFaultCount = this.CheckDeviceInfoMapper.getHavePicCount(mapFault);
				picMassSuccessCount = this.CheckDeviceInfoMapper.getPicMassCount(mapSuccess);
				picMassFaultCount = this.CheckDeviceInfoMapper.getPicMassCount(mapFault);
				resultPojoMap.put("netStatusSuccessCount", netStatusSuccessCount);
				resultPojoMap.put("netStatusFaultCount", netStatusFaultCount);
				resultPojoMap.put("picHaveSuccessCount", picHaveSuccessCount);
				resultPojoMap.put("picHaveFaultCount", picHaveFaultCount);
				resultPojoMap.put("picMassSuccessCount", picMassSuccessCount);
				resultPojoMap.put("picMassFaultCount", picMassFaultCount);
			}else if(devTypeCode.equals("REPDEVTYPE03")){//卡口；
				netStatusSuccessCount = this.CheckDeviceInfoMapper.getNetStatusCount(mapSuccess);
				netStatusFaultCount = this.CheckDeviceInfoMapper.getNetStatusCount(mapFault);
				picHaveSuccessCount = this.CheckDeviceInfoMapper.getHavePicCount(mapSuccess);
				picHaveFaultCount = this.CheckDeviceInfoMapper.getHavePicCount(mapFault);
				picMassSuccessCount = this.CheckDeviceInfoMapper.getPicMassCount(mapSuccess);
				picMassFaultCount = this.CheckDeviceInfoMapper.getPicMassCount(mapFault);
				DataStatusSuccessCount = this.CheckDeviceInfoMapper.getDaleyDateStatusCount(mapSuccess);
				dataStatusFaultCount = this.CheckDeviceInfoMapper.getDaleyDateStatusCount(mapFault);
				daleyStatusSuccessCount = this.CheckDeviceInfoMapper.getDaleyDateStatusCount(mapSuccess);
				daleyStatusFaultCount = this.CheckDeviceInfoMapper.getDaleyDateStatusCount(mapFault);
				resultPojoMap.put("netStatusSuccessCount", netStatusSuccessCount);
				resultPojoMap.put("netStatusFaultCount", netStatusFaultCount);
				resultPojoMap.put("picHaveSuccessCount", picHaveSuccessCount);
				resultPojoMap.put("picHaveFaultCount", picHaveFaultCount);
				resultPojoMap.put("picMassSuccessCount", picMassSuccessCount);
				resultPojoMap.put("picMassFaultCount", picMassFaultCount);
				resultPojoMap.put("DataStatusSuccessCount", DataStatusSuccessCount);
				resultPojoMap.put("dataStatusFaultCount", dataStatusFaultCount);
				resultPojoMap.put("daleyStatusSuccessCount", daleyStatusSuccessCount);
				resultPojoMap.put("daleyStatusFaultCount", daleyStatusFaultCount);
			}else if(devTypeCode.equals("REPDEVTYPE04")){//电警
				netStatusSuccessCount = this.CheckDeviceInfoMapper.getNetStatusCount(mapSuccess);
				netStatusFaultCount = this.CheckDeviceInfoMapper.getNetStatusCount(mapFault);
				picHaveSuccessCount = this.CheckDeviceInfoMapper.getHavePicCount(mapSuccess);
				picHaveFaultCount = this.CheckDeviceInfoMapper.getHavePicCount(mapFault);
				picMassSuccessCount = this.CheckDeviceInfoMapper.getPicMassCount(mapSuccess);
				picMassFaultCount = this.CheckDeviceInfoMapper.getPicMassCount(mapFault);
				DataStatusSuccessCount = this.CheckDeviceInfoMapper.getDaleyDateStatusCount(mapSuccess);
				dataStatusFaultCount = this.CheckDeviceInfoMapper.getDaleyDateStatusCount(mapFault);
				resultPojoMap.put("netStatusSuccessCount", netStatusSuccessCount);
				resultPojoMap.put("netStatusFaultCount", netStatusFaultCount);
				resultPojoMap.put("picHaveSuccessCount", picHaveSuccessCount);
				resultPojoMap.put("picHaveFaultCount", picHaveFaultCount);
				resultPojoMap.put("picMassSuccessCount", picMassSuccessCount);
				resultPojoMap.put("picMassFaultCount", picMassFaultCount);
				resultPojoMap.put("DataStatusSuccessCount", DataStatusSuccessCount);
				resultPojoMap.put("dataStatusFaultCount", dataStatusFaultCount);
			}else if(devTypeCode.equals("REPDEVTYPE08")){//诱导
				netStatusSuccessCount = this.CheckDeviceInfoMapper.getNetStatusCount(mapSuccess);
				netStatusFaultCount = this.CheckDeviceInfoMapper.getNetStatusCount(mapFault);
				resultPojoMap.put("netStatusSuccessCount", netStatusSuccessCount);
				resultPojoMap.put("netStatusFaultCount", netStatusFaultCount);
			}else{//地磁、微波、线圈
				netStatusSuccessCount = this.CheckDeviceInfoMapper.getNetStatusCount(mapSuccess);
				netStatusFaultCount = this.CheckDeviceInfoMapper.getNetStatusCount(mapFault);
				picMassSuccessCount = this.CheckDeviceInfoMapper.getPicMassCount(mapSuccess);
				picMassFaultCount = this.CheckDeviceInfoMapper.getPicMassCount(mapFault);
				DataStatusSuccessCount = this.CheckDeviceInfoMapper.getDaleyDateStatusCount(mapSuccess);
				dataStatusFaultCount = this.CheckDeviceInfoMapper.getDaleyDateStatusCount(mapFault);
				resultPojoMap.put("netStatusSuccessCount", netStatusSuccessCount);
				resultPojoMap.put("netStatusFaultCount", netStatusFaultCount);
				resultPojoMap.put("picMassSuccessCount", picMassSuccessCount);
				resultPojoMap.put("picMassFaultCount", picMassFaultCount);
				resultPojoMap.put("DataStatusSuccessCount", DataStatusSuccessCount);
				resultPojoMap.put("dataStatusFaultCount", dataStatusFaultCount);
			}
			resultPojo.setResultList(resultPojoMap);
			return resultPojo;
		} catch (Exception e) {
			// TODO: handle exception
			LoggerHelper.LOG.error(e);
			throw e;
		}
	}
	
	//-----------------------------私有方法开始---------------------------------------//
	private Map<String, Object> getSelectMap(String DevId,String devTypeCode,String devName,String ledType,String devStatusCode,String isPingConnect,String checkResultCode,String devAreaCode,String isDelayData,String isHightPackage,String isHightResponse,String isHaveData,String devFactory,String searchFlag,String beginLastPassTime,String endLastPassTime,String isPhotoSuccess,String repStatusCode,String project,String company,String picStatusFlag){
		Map<String, Object> map = new HashMap<>();
		map.put("DevId", DevId);
		map.put("devTypeCode",devTypeCode);
		map.put("devName", devName);
		map.put("ledType",ledType);
		map.put("devStatusCode", devStatusCode);
		map.put("isPingConnect",isPingConnect);
		map.put("checkResultCode", checkResultCode);
		map.put("devAreaCode", devAreaCode);
		map.put("isDelayData", isDelayData);
		map.put("isHightPackage",isHightPackage);
		map.put("isHightResponse", isHightResponse);
		map.put("isHaveData", isHaveData);
		map.put("searchFlag", searchFlag);
		map.put("devFactory",devFactory);
		map.put("beginLastPassTime", beginLastPassTime);
		map.put("endLastPassTime",endLastPassTime);
		map.put("isPhotoSuccess", isPhotoSuccess);
		map.put("repStatusCode",repStatusCode);
		map.put("company", company);
		map.put("project",project);
		map.put("picStatusFlag",picStatusFlag);
		return map;
	}


}
